package com.sihan.swvp.action.sys;


import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.sihan.swvp.action.BaseAction;
import com.sihan.swvp.entity.sys.Config;
import com.sihan.swvp.service.sys.ConfigService;
import com.sihan.swvp.service.sys.LogService;
@Controller
@RequestMapping("/SysConfig")
public class SysConfigAction extends BaseAction{

	@Autowired
	public ConfigService configService;
	@Autowired
	public LogService logService;
	
	@ResponseBody
	@RequestMapping(value="/getConfigPage")
	public Page<Map<String, Object>> getConfigPage(@Param("page")Integer page,@Param("limit")Integer limit){
		return configService.getConfigPage(page, limit);
	}
	
	@ResponseBody
	@RequestMapping(value="/getConfig")
	public Config getConfig(){
		return configService.getConfig();
	}
	 
	@ResponseBody
	@RequestMapping(value="/editSysConfig")
	public Object editSysConfig(@Param("maxsession")Integer maxsession,@Param("maxconcurrent")Integer maxconcurrent){
		try {
			Config config = new Config();
			config.setMaxsession(maxsession);
			config.setMaxconcurrent(maxconcurrent);
			configService.editSysConfig(config);
			getSession().setMaxInactiveInterval(maxsession * 60);
			logService.addUserLog("系统设置", "系统设置", getLoginUser().getId(), "会话过期时间："+maxsession+",最大登陆数量："+maxconcurrent,getRemoteAddr(),1,1);
			return successMsg();
		} catch (Exception e) {
			logService.addUserLog("系统设置", "系统设置", getLoginUser().getId(), "会话过期时间："+maxsession+",最大登陆数量："+maxconcurrent,getRemoteAddr(),0,1);
			return failMsg("服务器异常");
		}
	}

}
